package com.neuedu.springbootmy12306.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.neuedu.springbootmy12306.entity.Category;
import com.neuedu.springbootmy12306.entity.Pager;
import com.neuedu.springbootmy12306.entity.Result;
import com.neuedu.springbootmy12306.mapper.CategoryMapper;
import com.neuedu.springbootmy12306.service.CategoryService;

@Service
@Transactional
public class CategoryServiceImpl implements CategoryService {

	@Autowired
	private CategoryMapper categoryMapper;

	@Override
	public List<Category> findAll() {
		return categoryMapper.findAll();
	}

	@Override
	public List<Category> findListByPager(Pager<Category> pager) {
		return categoryMapper.findListByPager(pager);
	}

	@Override
	public Integer findTotalByPager(Pager<Category> pager) {
		return categoryMapper.findTotalByPager(pager);
	}

	@Override
	public Result add(Category category) {
		Result result = new Result(false, "新增商品分类失败！");
		boolean ret = categoryMapper.add(category);
		if (ret) {
			result = new Result(true, "新增商品分类成功！");
		}
		return result;
	}

	@Override
	public Result edit(Category category) {
		Result result = new Result(false, "修改商品分类失败！");
		boolean ret = categoryMapper.edit(category);
		if (ret) {
			result = new Result(true, "修改商品分类成功！");
		}
		return result;
	}

	@Override
	public Result deleteByIds(List<Category> ids) {
		Result result = new Result(false, "删除商品分类失败！");
		boolean ret = categoryMapper.deleteByIds(ids);
		if (ret) {
			result = new Result(true, "删除商品分类成功！");
		}
		return result;
	}

}
